import bluetooth

##btaddress = '00:16:b8:e7:9e:ff'
##sockfd = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
##sockfd.connect((btaddress, 1)) # BT Address
##sockfd.send('ATZ\r')
##sockfd.send('AT+CMGF=0\r')
##sockfd.send('AT+CSCA="+4528886598"\r') # Client TIM ITA
##sockfd.send('AT+CMGS="+4528886598"\r') # TO PhoneNumber
##sockfd.send('Messaggio da mandare...\n')
##sockfd.send(chr(26)) # CTRL+Z
##sockfd.close()



btaddress = '00:16:b8:e7:9e:ff'
sockfd = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sockfd.connect((btaddress, 1)) # BT Address
sockfd.setblocking(False)

def send(str):
    sockfd.send(str)
    while True:
        data = sockfd.recv(10)
        if data != '':
            print data,'.',
            sleep(0.2)
        else:
            print
            return None

#sockfd.send('ATZ\r')
#sockfd.send('AT+CMGF=0\r')
#sockfd.send('AT+CSMS=0"\r') # Client TIM ITA
#sockfd.send('AT+CMGS=23\r') # TO PhoneNumber
#sockfd.send('>0011000B91828856890000AA0AE8329BFD4697D9EC37\n')
#sockfd.send(chr(26)) # CTRL+Z
#sockfd.close()
